package com.ruoyi.quality.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quality.domain.CommonConstructionSpecifications;
import com.ruoyi.quality.service.ICommonConstructionSpecificationsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 施工规范分类Controller
 * 
 * @author lxg
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/quality/specifications")
public class CommonConstructionSpecificationsController extends BaseController
{
    @Autowired
    private ICommonConstructionSpecificationsService commonConstructionSpecificationsService;

    /**
     * 查询施工规范分类列表
     */
    @PreAuthorize("@ss.hasPermi('quality:specifications:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonConstructionSpecifications commonConstructionSpecifications)
    {
        List<CommonConstructionSpecifications> list = commonConstructionSpecificationsService.selectCommonConstructionSpecificationsList(commonConstructionSpecifications);
        return getDataTable(list);
    }

    /**
     * 导出施工规范分类列表
     */
    @PreAuthorize("@ss.hasPermi('quality:specifications:export')")
    @Log(title = "施工规范分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommonConstructionSpecifications commonConstructionSpecifications)
    {
        List<CommonConstructionSpecifications> list = commonConstructionSpecificationsService.selectCommonConstructionSpecificationsList(commonConstructionSpecifications);
        ExcelUtil<CommonConstructionSpecifications> util = new ExcelUtil<CommonConstructionSpecifications>(CommonConstructionSpecifications.class);
        util.exportExcel(response, list, "施工规范分类数据");
    }

    /**
     * 获取施工规范分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('quality:specifications:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commonConstructionSpecificationsService.selectCommonConstructionSpecificationsById(id));
    }

    /**
     * 新增施工规范分类
     */
    @PreAuthorize("@ss.hasPermi('quality:specifications:add')")
    @Log(title = "施工规范分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonConstructionSpecifications commonConstructionSpecifications)
    {
        return toAjax(commonConstructionSpecificationsService.insertCommonConstructionSpecifications(commonConstructionSpecifications));
    }

    /**
     * 修改施工规范分类
     */
    @PreAuthorize("@ss.hasPermi('quality:specifications:edit')")
    @Log(title = "施工规范分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonConstructionSpecifications commonConstructionSpecifications)
    {
        return toAjax(commonConstructionSpecificationsService.updateCommonConstructionSpecifications(commonConstructionSpecifications));
    }

    /**
     * 删除施工规范分类
     */
    @PreAuthorize("@ss.hasPermi('quality:specifications:remove')")
    @Log(title = "施工规范分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commonConstructionSpecificationsService.deleteCommonConstructionSpecificationsByIds(ids));
    }
}
